# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : 元素的基本操作。老师的.py
# Author : asus
# Date_Time:2022/4/21 15:27
# Description :
# ----------
from selenium import webdriver
import time
from selenium.webdriver.common.by import By


def foo1():
    """
    模拟键盘输入sendkeys()
    清空输入框clear()
    :return: None
    """
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get("https://www.baidu.com/")

    driver.find_element(By.NAME, "wd").clear()
    driver.find_element(By.NAME, "wd").send_keys("51放假安排")  # send_keys() 模拟键盘输入
    time.sleep(3)

    # 在输入框输入之前一定先清空一次
    driver.find_element(By.NAME, "wd").clear()  # 清空input输入框，只针对<input>
    driver.find_element(By.NAME, "wd").send_keys("国庆放假安排")
    time.sleep(3)

    driver.quit()

def foo2():
    """

    :return: None
    """
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get("https://www.baidu.com/")

    el = driver.find_element(By.XPATH,'//*[@id="s-top-left"]/a[1]')

    #获取新闻元素的href属性
    el_att = el.get_attribute('href')
    print(el_att)

    #获取元素文本text
    text = el.text
    print(text)
    driver.quit()


if __name__ == "__main__":
    # foo1()
    foo2()